package com.allianz.webapps.controllers;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.allianz.webapps.https.interfaces.type002.pojo.Pkg;
import com.allianz.webapps.https.interfaces.type003.Type003;
import com.allianz.webapps.https.interfaces.type003.pojo.Detail;
import com.fasterxml.jackson.databind.ObjectMapper;
//http://localhost:8080/pad_marketing/main/type003getDecall.action
@Controller
@RequestMapping(value="main")
public class Type003Controller {
	
	@Autowired
	private ObjectMapper objectMapper;
	@Autowired
	private Type003 t3;
	
	@RequestMapping(value="type003getDecall")
	@ResponseBody
	public Detail type003getDecall(@RequestParam(value="jsonParam") String jsonParam, HttpServletRequest request,HttpServletResponse response) 
			throws Exception{
		Pkg  pkg = objectMapper.readValue(jsonParam, Pkg.class);
		String body=t3.requestLoginParam(pkg);
		JSONObject json=new JSONObject(body);
		ObjectMapper mapper = new ObjectMapper();
		Detail detail=null;
		String body1="";
		if (json.get("Body").equals(null)) {
			body1="";
		}else{
			body1=json.getString("Body");
			detail=mapper.readValue(body1, Detail.class);
		}
		return detail;
	}
	
	
}
